package com.smap.vector;

import java.util.List;

import com.smap.core.XY;

/**
 * a LineString
 * 
 * @author shen
 * 
 */
public class LineString extends Geometry {
	public LineString() {

	}

	public LineString(List<Point> pts) {
		for (Point pt : pts) {
			this.add(pt.toXY());
		}
	}

	@Override
	public boolean contains(XY point) {
		if (this.coordinates.size() < 2) {
			return false;
		}

		if (!super.contains(point)) {
			return false;
		}

		List<LineSegment> lines = this.getLineSegments();
		for (LineSegment lineSegment : lines) {
			if (lineSegment.contains(point)) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		LineString ls = new LineString();
		ls.add(0, 0).add(10, 10).add(30, 30).pack();
		boolean isContains = ls.contains(new XY(31, 31));
		System.out.println(isContains);
	}
}
